package com.oppo.taunt;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @author steve
 * @since 2021-12-03 0:05
 */

public class ContentUtil {

    public static String getContent() {
        RestTemplate restTemplate = new RestTemplate();
        try {
            ResponseEntity<Map> entity = restTemplate.getForEntity("https://api.nextrt.com/V1/Dutang"
                    , Map.class);
            HttpStatus statusCode = entity.getStatusCode();
            if (statusCode.is2xxSuccessful()) {
                List data = (List) entity.getBody().get("data");
                Map<String, String> contentMap = (Map<String, String>) data.get(0);
                return contentMap.get("content");
            }
        } catch (RestClientException e) {
            return "汤碗都碎了";
        }
        return "今天没有鸡汤";
    }


}
